#!/bin/bash -ex

source /usr/sbin/get_hive_home.sh

sudo -E -u hive nohup ${HIVE_HOME}/bin/hiveserver2 > /var/log/${HIVE_PACKAGE}/hiveserver2.out 2>&1  &
sleep 60 # wait for hive server to startup completely

HDP_VERSION=$(ls /usr/hdp/ | grep -e '^2\|^3')
if [[ "$HDP_VERSION" =~ ^2 ]]
then
    echo "Hadoop 2, not installing tez"
else
    sudo -E -u hdfs hadoop fs -mkdir -p /user/anonymous
    sudo -E -u hdfs hadoop fs -chown anonymous:anonymous /user/anonymous
    sudo -E -u hdfs hadoop fs -mkdir -p /apps/tez
    sudo -E -u hdfs hadoop fs -copyFromLocal /usr/hdp/${HDP_VERSION}/tez/lib/tez.tar.gz /apps/tez
fi
